package com.water.guider.highlight

import android.graphics.Canvas
import android.graphics.Paint
import kotlin.math.hypot

/**
 * 圆形的高亮区域.
 */
class CircleHighlight : IHighlight {

    override var width = 0
    override var height = 0
    var padding = 0
    var radius = 0

    constructor()

    @JvmOverloads
    constructor(width: Int, height: Int, padding: Int = 0) {
        this.width = width
        this.height = height
        this.padding = padding
        init()
    }

    override fun init() {
        radius = hypot(width.toDouble(), height.toDouble()).toInt() / 2 + padding
        width = radius * 2
        height = radius * 2
    }

    override var ringWidth: Int = 0

    override fun draw(canvas: Canvas, paint: Paint, x: Int, y: Int) {
        canvas.drawCircle(x.toFloat(), y.toFloat(), radius.toFloat(), paint)
    }

    override fun draw(canvas: Canvas, paint: Paint, x: Int, y: Int, value: Int) {
        val circleRadius = if (value >= radius) radius else value
        canvas.drawCircle(x.toFloat(), y.toFloat(), circleRadius.toFloat(), paint)
    }

    override val max: Int
        get() = width.coerceAtLeast(height)
}